import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:iidx_progress_tool/components/musiclistcomponent/filter_model.dart';
import 'package:iidx_progress_tool/data/consts/level.dart';

class LevelDropdownMenu extends StatefulWidget {
  FilterModel filterModel;

  LevelDropdownMenu({required this.filterModel});

  @override
  State<StatefulWidget> createState() {
    return _LevelDropdownMenuState();
  }
}

class _LevelDropdownMenuState extends State<LevelDropdownMenu> {
  var _dropdownMenuController = TextEditingController();


  @override
  Widget build(BuildContext context) {
    return DropdownMenu<Level>(
      controller: _dropdownMenuController,
      dropdownMenuEntries: Level.values.map<DropdownMenuEntry<Level>>(
          (Level l) {
            return DropdownMenuEntry(value: l, label: 'Lv. ${l.value}');
          }
      ).toList(),
      onSelected: (value) {
        setState(() {
          widget.filterModel.onLevelSelected(value);
        });
      },
      leadingIcon: IconButton(
        icon: Icon(Icons.clear),
        onPressed: _clearSelection,
      ),
      menuHeight: 500,
      width: MediaQuery.of(context).size.width * 0.5,
      hintText: '选择Level',
    );
  }

  void _clearSelection() {
    _dropdownMenuController.clear();
    widget.filterModel.onLevelSelected(null);
  }
}